var mariaSqlClient = require("mariasql");

var MariaDb = MariaDb || {
	set_database : function(host, username, password, databaseName) {
		this.host = host;
		this.username = username;
		this.password = password;
		this.databaseName = databaseName;
		
		this.sqlClient = new mariaSqlClient({
			host     : this.host,
			user     : this.username,
			password : this.password,
			db 		 : this.databaseName
		});
	},
	// connect : function() {
	// 	this.connection = mariasql.createConnection({
	// 		host     : this.host,
	// 		user     : this.username,
	// 		password : this.password,
	// 		database : this.databaseName
	// 	}); 
	// },
	query : function(queryText, values, options, callback)
	{
		//this.sqlClient.query(queryText, this.handleEventQueryResult.bind(this, callback, thisForCallback));
		this.sqlClient.query(queryText, values, options, callback);
		this.sqlClient.end();
	},
	handleEventQueryResult : function(callback, thisForCallback, error, rowsRetrieved, fields) 
	{
		if (error) 
			throw error;

		callback.call(thisForCallback, rowsRetrieved, fields);
	}
};

module.exports = MariaDb;